<?php

namespace App\Http\Middleware;

use App\ZL\Library\ErrorCode;
use Closure;
use Illuminate\Support\Facades\Auth;

class CheckXcxLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $session_id = request()->header('session-id');
        if(!$session_id){
//            Auth::loginUsingId(1);
            if($request->not_check!=null){
                return $next($request);
            }
            return responseZK(ErrorCode::$notSessionIdError['code'],[],ErrorCode::$notSessionIdError['msg']);
        }
        $user_id = getSessionField('id');
        if(!$user_id){
            return responseZK(ErrorCode::$XcxNotLoginError['code'],[],ErrorCode::$XcxNotLoginError['msg']);
        }

        Auth::loginUsingId($user_id);
        return $next($request);
    }
}
